﻿/*
* Activity Tracking Log v0.1.1 - http://activitytrackinglog.codeplex.com
* Activity Tracking Log for ASP.Net & ASP.Net MVC
* Copyright (c) 2011 Vadim Burac
* Licensed under the Microsoft Public License (Ms-PL)
* http://activitytrackinglog.codeplex.com/license
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using ActivityTrackingLog.Utils;

namespace ActivityTrackingLog.Configuration
{
    public abstract class BaseConfigSection : ConfigurationSection
    {
        #region ctors

        public BaseConfigSection()
        {
        }

        #endregion

        #region helpers

        [ConfigurationProperty("enabled", IsRequired = true)]
        public bool Enabled
        {
            get
            {
                bool res = true;
                if (null != this["enabled"] && bool.TryParse(this["enabled"].ToString(), out res))
                    return res;

                return true;
            }
        }

        protected T GetConfigValue<T>(string settingName, T defaultVal = default(T))
        {
            if (null != this[settingName])
                return this[settingName].ToString().Convert<T>(defaultVal);

            return defaultVal;
        }

        #endregion

        #region helpers

        public override string ToString()
        {
            return string.Format("Enabled: {0}", Enabled);
        }

        #endregion
    }
}
